package com.zhongge.service.imp;

import com.zhongge.entity.PageData;
import com.zhongge.entity.Student;
import com.zhongge.mapper.StudentRepository;
import com.zhongge.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
 * @ClassName StudentServiceImpl
 * @Description TODO
 * @Author zhongge
 * @Version 1.0
 */
@Service
public class StudentServiceImpl implements StudentService {
    @Resource
    private StudentRepository studentRepository;
    @Override
    public PageData<Student> pageSel(int pageSize, int pageNum) {
        //首先进行页码和页数的封装
        PageRequest of = PageRequest.of(pageSize - 1, pageNum);
        Page<Student> all = studentRepository.findAll(of);
        PageData<Student> studentPageData = new PageData<>();
        studentPageData.setTotal(all.getTotalElements());
        studentPageData.setRows(all.getContent());
        return studentPageData;
    }
}
